<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/public/header.jsp"%>
<%
    String callback = request.getParameter("callback");
    String gd_content_id = request.getParameter("gd_content_id") == null ? "" : request.getParameter("gd_content_id");
    String gd_id = request.getParameter("gd_id") == null ? "" : request.getParameter("gd_id");
    boolean isAdd = "".equals(gd_id);
    int flag = 0;
    if(!isAdd){
    	flag = 1;
    }
%>
<html>
	<head>
		<title><%=isAdd?"新建工单":"编辑工单" %></title>
		<link href="<%=contextPath%>/public/css/smart_wizard_vertical.css" rel="stylesheet"	type="text/css">
		<script type="text/javascript" src="<%=contextPath%>/public/js/jquery.smartWizard.js"></script>
		<link  rel="stylesheet"  href  ="<%=contextPath%>/public/swfupload/css/swfupload.css">
		<style>
			.td1{
				padding-top:10px;
				padding-bottom:5px;
				font-size: 12px;
				background-color: #c0ebd7;
				width:20%;
			}
			.td2{
				padding:5px;
			}
			.tdg{
			padding-top:10px;
			padding-bottom:5px;
			font-size: 12px;
			background-color: #c0ebd7;
			width:20%;
		}
		.tdb{
			padding:5px;
			width:30%;
		}
		</style>
		<script  type="text/javascript"  src="<%=contextPath%>/core/js/datastructs.js"  ></script>
		<script  type="text/javascript"  src="<%=contextPath%>/core/js/sys.js"  ></script>
		<script  type="text/javascript"  src="<%=contextPath%>/core/js/prototype.js"  ></script>
		<script type="text/javascript" src="<%=contextPath%>/public/swfupload/js/attachMenu.js"></script>
		<script type="text/javascript" src="<%=contextPath%>/public/swfupload/js/Menu.js"></script>
		<script  type="text/javascript"  src="<%=contextPath%>/public/swfupload/js/swfupload.js"  ></script>
		<script  type="text/javascript"  src="<%=contextPath%>/public/swfupload/js/fileprogress.js"  ></script>
		<script  type="text/javascript"  src="<%=contextPath%>/public/swfupload/js/handlers.js"  ></script>
		<script  type="text/javascript"  src="<%=contextPath%>/public/swfupload/js/swfupload.queue.js"  ></script>
		<script type="text/javascript">
		var combogridTarget;
			function leaveCallback(obj,context){
				if(context.fromStep == 1){
					return jQuery('#gdForm').form('validate');
				}
				return true;
			}
			var lastIndex=-1;
			var fb_lastIndex=-1;
			var m_lastIndex=-1;
			function showCallback(obj,context){
				if(context.toStep == 2){//显示任务计划
					jQuery('#table').datagrid('acceptChanges');
					var data = jQuery('#table').datagrid('getData');
					jQuery('#table').datagrid('loadData',data);
					jQuery('#table').datagrid('endEdit', lastIndex);
					jQuery('#table').datagrid('beginEdit', lastIndex);
				}
				if(context.toStep == 3){//显示分包预算
					jQuery('#fb_detail').datagrid('acceptChanges');
					var data = jQuery('#fb_detail').datagrid('getData');
					jQuery('#fb_detail').datagrid('loadData',data);
					jQuery('#fb_detail').datagrid('endEdit', fb_lastIndex);
					jQuery('#fb_detail').datagrid('beginEdit', fb_lastIndex);
				}
				if(context.toStep == 4){//显示材料预算
					jQuery('#material').datagrid('acceptChanges');
					var data = jQuery('#material').datagrid('getData');
					jQuery('#material').datagrid('loadData',data);
					jQuery('#material').datagrid('endEdit', m_lastIndex);
					jQuery('#material').datagrid('beginEdit', m_lastIndex);
				}
			}
			var typeArr=new Array("内部班组","外部分包商");
			var swfupload;
			var flag = '<%=flag%>';
			jQuery(document).ready(function() {
				var gdAdminId="";
				var gdAdminName="";
				var customerId="";
				var customerName="";
				var fbId="";
				var fbName="";
				jQuery('#table').datagrid({
				  	title:'任务计划',
				  	iconCls:'icon-edit',
				  	<%=isAdd?"":"url:'"+contextPath+"/springMVC/gd/listPageGDPlan?gd_id="+gd_id+"&gd_content_id="+gd_content_id+"',"%>
				  	rownumbers:true,
					fitColumns:true,
					singleSelect:true,
					frozenColumns:[[
						{field:'ck',checkbox:true},
					    {title:'计划id',field:'id',hidden:true}
					]],
					columns:[[
						{title:'计划开始时间',field:'plan_start_time',width:30,align:'center',editor:{
							type:'datebox'
						}},
						{title:'计划截至时间',field:'plan_end_time',width:30,align:'center',editor:{
							type:'datebox'
						}},
						{title:'计划工作内容',field:'plan_content',width:100,align:'center',editor:{
							type:'textarea'
						}}
					]],
					onBeforeLoad:function(){
						jQuery(this).datagrid('rejectChanges');
					},
					onClickCell:function(rowIndex,field,value){
						if (lastIndex != rowIndex){
							jQuery('#table').datagrid('endEdit', lastIndex);
							jQuery('#table').datagrid('beginEdit', rowIndex);
							var ed = jQuery('#table').datagrid('getEditor', {index:rowIndex,field:field});
							if(ed == null){
								ed = jQuery('#table').datagrid('getEditor', {index:rowIndex,field:'plan_content'});
							}
							jQuery(ed.target).select();
						}
						lastIndex = rowIndex;
					},
					pageSize:10,
					pageList : [10,50,100],  
					pagination:true,
					toolbar:[
						{
							id:'add',
							text:'新建任务计划',
							disabled:false,
							iconCls:'icon-add',
							handler:function(){
								addRow();
							}
						},'-',{
						id:'save',
						text:'保存修改',
						disabled:false,
						iconCls:'icon-save',
						handler:function(){
							jQuery('#table').datagrid('acceptChanges');
							lastIndex =-1;
						}
						},'-',{
						id:'delete',
						text:'删除',
						disabled:false,
						iconCls:'icon-remove',
						handler:function(){
							deleteRow();
						}
					}
				   ]
				});
				jQuery('#fb_detail').datagrid({
				  	title:'分包预算',
				  	iconCls:'icon-edit',
				  	<%=isAdd?"":"url:'"+contextPath+"/springMVC/gd/listPageFBDetail?gd_id="+gd_id+"',"%>
				  	rownumbers:true,
				  	singleSelect:true,
					fitColumns:true,
					frozenColumns:[[
						{field:'ck',checkbox:true},
					    {title:'分包结算id',field:'id',hidden:true},
					    {title:'分包栏目id',field:'fb_item_id',hidden:true}
					]],
					columns:[[
						{title:'栏目名称',field:'fb_item_name',width:50,align:'center',editor:{
							type:'combobox',
							options:{
							    url:'<%=contextPath%>/springMVC/group/getFBItem',  
							    valueField:'id',  
							    textField:'name',
							    onHidePanel:function(){
							    	var pRow = jQuery('#fb_detail').datagrid('getRows')[fb_lastIndex];
									pRow.fb_item_id = jQuery(this).combobox('getValue');
									pRow.fb_item_name = jQuery(this).combobox('getText');
									jQuery('#fb_detail').datagrid('getData').rows[fb_lastIndex]=pRow;
									var data = jQuery('#fb_detail').datagrid('getData');
									jQuery('#fb_detail').datagrid('loadData',data);
									
									jQuery('#fb_detail').datagrid('endEdit', fb_lastIndex);
									jQuery('#fb_detail').datagrid('beginEdit', fb_lastIndex);
							    }
							}
						}},
						{title:'预算成本',field:'budget',width:50,align:'center',editor:{
							type:'numberbox',
							options:{
								precision:2
							}
						}},
						{title:'预算备注',field:'budget_remark',width:100,align:'center',editor:{
							type:'textarea'
						}}
					]],
					onBeforeLoad:function(){
						jQuery(this).datagrid('rejectChanges');
					},
					onClickCell:function(rowIndex,field,value){
						if (fb_lastIndex != rowIndex){
							jQuery('#fb_detail').datagrid('endEdit', fb_lastIndex);
							jQuery('#fb_detail').datagrid('beginEdit', rowIndex);
							var ed = jQuery('#fb_detail').datagrid('getEditor', {index:rowIndex,field:field});
							if(ed == null){
								ed = jQuery('#fb_detail').datagrid('getEditor', {index:rowIndex,field:'budget'});
							}
							jQuery(ed.target).select();
						}
						fb_lastIndex = rowIndex;
					},
					pageSize:10,
					pageList : [10,50,100],  
					pagination:true,
					toolbar:[
						{
							id:'add',
							text:'添加预算栏目',
							disabled:false,
							iconCls:'icon-add',
							handler:function(){
								addFBRow();
							}
						},'-',{
						id:'save',
						text:'保存修改',
						disabled:false,
						iconCls:'icon-save',
						handler:function(){
							jQuery('#fb_detail').datagrid('acceptChanges');
							fb_lastIndex =-1;
						}
						},'-',{
						id:'delete',
						text:'删除',
						disabled:false,
						iconCls:'icon-remove',
						handler:function(){
							deleteFBRow();
						}
					}
				   ]
				});
				
				//----新增材料预算
					//注册combogrid
					jQuery.extend(jQuery.fn.datagrid.defaults.editors, {
						   combogrid: {
							    init: function(container, options){
								    var input = jQuery('<input  type="text" class="datagrid-editable-input">').appendTo(container);
								   	input.combogrid(options);
								    return input;
						    	},
						    	distroy:function(target){
						    		jQuery(target).combogrid('distroy');
						    	},
							    getValue: function(target){
							    	return jQuery(target).combogrid('getValue');
							    },
							    setValue: function(target, value){
							   	 	jQuery(target).combogrid('setValue',value);
							    },
							    resize: function(target, width){
							    	combogridTarget = target;
								    jQuery(target).combogrid('resize',width);
							    }
						    }
						 });
				jQuery("#mSearchValue").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 domSearch();
			       	} 
			   	}); 
				jQuery("#material_type_id").combotree({
					url:'<%=contextPath %>/springMVC/group/getSystemTypeTree?type=0',
					method:'POST',
					animate:true,
					lines:true,
					onChange:function(){
						domSearch();
					}
				});
				jQuery('#mtb').hide();
				
				jQuery('#material').datagrid({
				  	title:'材料预算',
				  	iconCls:'icon-edit',
				  	<%=isAdd?"":"url:'"+contextPath+"/springMVC/gd/listPageMaterial?gd_id="+gd_id+"',"%>
				  	rownumbers:true,
				  	singleSelect:true,
					fitColumns:true,
					frozenColumns:[[
						{field:'ck',checkbox:true},
					    {title:'材料id',field:'material_id',hidden:true}
					]],
					columns:[[
						{title:'材料编号',field:'code',width:100,align:'center',editor:{
							type:'combogrid',
							options:{
								url: '<%=contextPath %>/springMVC/warehouse/listPageMaterial',
							    panelWidth:750,
							    panelHeight:355,
							    rownumbers:true,
							    fitColumns:true,
							    columns: [[  
							       {field:'id',title:'主键',hidden:true},  
							       {field:'material_type_name',title:'材料类别',width:100,align:'center'},
							       {field:'code',title:'材料编号',width:100,align:'center'},
							       {field:'name',title:'材料名称',width:150,align:'center'},
							       {field:'format_type',title:'规格/型号',width:100,align:'center'},
							       {field:'unit_name',title:'单位',width:50,align:'center'}
							    ]],
							    onBeforeLoad:function(param){
									var mSearchValue = jQuery('#mSearchValue').val();
									var material_type_id = jQuery('#material_type_id').combotree('getValue');
									param.searchValue=mSearchValue;
									param.material_type_id=material_type_id;
								},
							    toolbar:'#mtb',
							    pageList : [10,50,100],  
								pagination:true,
								onClickRow:function(rowIndex,rowData){
									if(checkSameProduct1(rowData,jQuery('#material').datagrid('getData').rows)){
										var pRow = jQuery('#material').datagrid('getRows')[m_lastIndex];
										pRow.material_id = rowData.id;
										pRow.code = rowData.code;
										pRow.name = rowData.name;
										pRow.unit_name = rowData.unit_name;
										pRow.format_type = rowData.format_type;
										jQuery('#material').datagrid('getData').rows[m_lastIndex]=pRow;
										var data = jQuery('#material').datagrid('getData');
										jQuery('#material').datagrid('loadData',data);
										
										jQuery('#material').datagrid('endEdit', m_lastIndex);
										jQuery('#material').datagrid('beginEdit', m_lastIndex);
									}else{
										jQuery.messager.alert("提示","选择的材料已经存在");
									}
								}
							}
						}},
						{title:'材料名称',field:'name',width:200,align:'center'},
						{title:'规格/型号',field:'format_type',width:200,align:'center'},
						{title:'单位',field:'unit_name',width:50,align:'center'},
						{title:'预算数量',field:'num',width:100,align:'center',editor:{
							type:'numberbox',
							options:{
								min:0,
								precision:2
							}
						}},
						{title:'备注',field:'remark',width:260,align:'center',editor:{
							type:'textarea'
						}}
					]],
					onBeforeLoad:function(){
						jQuery(this).datagrid('rejectChanges');
					},
					onClickCell:function(rowIndex,field,value){
						if (m_lastIndex != rowIndex){
							jQuery('#material').datagrid('endEdit', m_lastIndex);
							jQuery('#material').datagrid('beginEdit', rowIndex);
							var ed = jQuery('#material').datagrid('getEditor', {index:rowIndex,field:field});
							if(ed == null){
								ed = jQuery('#material').datagrid('getEditor', {index:rowIndex,field:'num'});
							}
							jQuery(ed.target).select();
						}
						m_lastIndex = rowIndex;
					},
					pageSize:10,
					pageList : [10,50,100],  
					pagination:true,
					toolbar:[
						{
							id:'add',
							text:'添加材料',
							disabled:false,
							iconCls:'icon-add',
							handler:function(){
								addMRow();
							}
						},'-',{
						id:'save',
						text:'保存修改',
						disabled:false,
						iconCls:'icon-save',
						handler:function(){
							jQuery('#material').datagrid('acceptChanges');
							m_lastIndex =-1;
						}
						},'-',{
						id:'delete',
						text:'删除',
						disabled:false,
						iconCls:'icon-remove',
						handler:function(){
							deleteMRow();
						}
					}
				   ]
				});
				
				if(flag == '1'){
					jQuery('#gdForm').form({
						onLoadSuccess:function(data){
							queueCompleteOver();
							gdAdminId=data.gd_admin_id;
							gdAdminName=data.gd_admin_name;
							customerId=data.customer_id;
							customerName=data.customer;
							fbId=data.gd_worker_id;
							fbName=data.gd_worker_name;
						}
					});
					jQuery('#gdForm').form("load",'<%=contextPath %>/springMVC/gd/getGDBaseById?gd_id=<%=gd_id%>&gd_content_id=<%=gd_content_id%>');
					jQuery.ajax({
						type:"POST",
						url:"<%=contextPath %>/springMVC/gd/getGDControl?gd_id=<%=gd_id%>",
						success:function(rtData){
							jQuery('#control').numberbox('setValue',rtData);
						}
					});
				}
				jQuery("#searchValue").keypress(function(e) { 
			    	// 回车键事件 
			     	if(e.which == 13) { 
			     		 doSearch();
			       	} 
			   	}); 
				jQuery("#searchValue1").keypress(function(e) { 
			    	// 回车键事件 
			     	if(e.which == 13) { 
			     		 doSearch1();
			       	} 
			   	}); 
				jQuery("#searchValuec").keypress(function(e) { 
			    	// 回车键事件 
			     	if(e.which == 13) { 
			     		 doSearchc();
			       	} 
			   	}); 
				// Smart Wizard 	
					jQuery('#wizard').smartWizard( {
						transitionEffect : 'slide',
						keyNavigation:false,
						labelFinish:'提交',
						labelNext:'下一步', // label for Next button
					    labelPrevious:'上一步', // label for Previous button
					    onLeaveStep:leaveCallback,
					    onShowStep:showCallback,
						onFinish:onFinishCallback
					});
					jQuery("#customer_type_id").combotree({
						url:'<%=contextPath%>/springMVC/group/getSystemTypeTree?type=1',
						method:'POST',
						animate:true,
						lines:true,
						onChange:function(){
							doSearchc();
						}
					});
					
				jQuery('#customer_id').combogrid({
					title:'客户选择',
					mode:"remote",
					loadMsg:'正在加载数据，请稍后......',
					panelWidth:550,
					panelHeight:400,
					url:"<%=contextPath%>/springMVC/crm/listPageCustomer",
					idField:"id",
					textField:"company",
					rownumbers:true,
					fitColumns:true,
					columns: [[
						{field:'id',hidden:true},
						{title:'客户类别',field:'type_name',width:200,align:'center'},
						{title:'公司名称',field:'company',width:200,align:'center'},
						{title:'联系人',field:'contact',width:200,align:'center'},
						{title:'TEL',field:'tel',width:200,align:'center'}
					]],
					toolbar:"#tbc",
					pageSize:10,
					pageList:[10,50,100],  
					pagination:true,
					onLoadSuccess:function(rtJson){
						jQuery('#customer_id').combogrid('setValue',customerId);
						jQuery('#customer_id').combogrid('setText',customerName);
					}
				});
				jQuery('#gd_admin_id').combogrid({
					title:'人员选择',
					mode:"remote",
					loadMsg:'正在加载数据，请稍后......',
					panelWidth:550,
					panelHeight:400,
					url:"<%=contextPath%>/springMVC/group/listPageUser",
					idField:"id",
					textField:"truename",
					rownumbers:true,
					fitColumns:true,
					columns: [[
						{field:'id',hidden:true},
						{field:'deptId',hidden:true},
						{field:'truename',title:'姓名',width:100},
						{field:'deptName',title:'所属部门',width:100},
						{field:'privName',title:'角色',width:100}
					]],
					toolbar:"#tb",
					pageSize:10,
					pageList:[10,50,100],  
					pagination:true,
					onChange:function(){
						var row = jQuery('#gd_admin_id').combogrid("grid").datagrid('getSelected');
						jQuery('#dept_id').val(row.deptId);
						jQuery('#dept_name').val(row.deptName);
					},
					onLoadSuccess:function(rtJson){
						jQuery('#gd_admin_id').combogrid('setValue',gdAdminId);
						jQuery('#gd_admin_id').combogrid('setText',gdAdminName);
					}
				});
				jQuery('#gd_worker_id').combogrid({
					idField:"id",
					textField:"worker_company",
					title:'分包商资料',
					panelWidth:550,
					panelHeight:400,
					rownumbers:true,
					url:'<%=contextPath%>/springMVC/crm/listPageWorker',
					loadMsg:'正在加载数据，请稍后......',
					fitColumns:true,
					frozenColumns:[[
					    {title:'主键',field:'id',hidden:true}
					]],
					columns:[[
						{title:'分包商类别',field:'type_id',width:200,align:'center',formatter:function(value,rowData,rowIndex){
							return typeArr[rowData.type_id];
						}},
						{title:'公司名称',field:'worker_company',width:200,align:'center'},
						{title:'负责人',field:'worker_person',width:200,align:'center'},
						{title:'联系方式',field:'contact',width:200,align:'center'}
					]],
					pageSize:10,
					pageList : [10,50,100],  
					pagination:true,
					toolbar:'#tb1',
					onChange:function(){
						var row = jQuery('#gd_worker_id').combogrid("grid").datagrid('getSelected');
						jQuery('#gd_worker_person').val(row.worker_person);
					},
					onLoadSuccess:function(rtJson){
						jQuery('#gd_worker_id').combogrid('setValue',fbId);
						jQuery('#gd_worker_id').combogrid('setText',fbName);
					}
				});
				
				
				jQuery('#company1_id').combogrid({
					title:'管理公司',
					mode:"remote",
					loadMsg:'正在加载数据，请稍后......',
					panelWidth:550,
					panelHeight:400,
					url:"<%=contextPath%>/springMVC/group/listPageCompany?type=1",
					idField:"id",
					textField:"company_name",
					rownumbers:true,
					fitColumns:true,
					columns: [[
						{field:'id',hidden:true},
						{title:'公司名称',field:'company_name',width:200,align:'center'}
					]],
					pageSize:10,
					pageList:[10,50,100],  
					pagination:true
				});
				jQuery('#company2_id').combogrid({
					title:'实施公司',
					mode:"remote",
					loadMsg:'正在加载数据，请稍后......',
					panelWidth:550,
					panelHeight:400,
					url:"<%=contextPath%>/springMVC/group/listPageCompany?type=2",
					idField:"id",
					textField:"company_name",
					rownumbers:true,
					fitColumns:true,
					columns: [[
						{field:'id',hidden:true},
						{title:'公司名称',field:'company_name',width:200,align:'center'}
					]],
					pageSize:10,
					pageList:[10,50,100],  
					pagination:true
				});
					
					var settings = {
				      flash_url : "<%=contextPath%>/public/swfupload/swfupload.swf",
				      upload_url: "<%=contextPath%>/springMVC/fileUpload/fileupload",
				      post_params: {
				    	 "module" : "<%=com.beaut.project.util.StaticData.GD_MODULE%>"
				      },
				      file_size_limit : "100 MB",
				      file_types : "*.*",
				      file_types_description : "All Files",
				      file_upload_limit : 100,
				      file_queue_limit : 0,
				      custom_settings : {
				        uploadArea : "fsUploadArea",
				        progressTarget : "fsUploadProgress",
				        startButtonId : "btnStart",
				        cancelButtonId : "btnCancel"
				      },
				      debug: false,
				      button_image_url: "<%=contextPath%>/public/swfupload/img/uploadx4.gif",
				      button_width: "65",
				      button_height: "29",
				      button_placeholder_id: "spanButtonUpload",
				      button_text: '<span class=\"textUpload\">上传附件</span>',
				      button_text_style: ".textUpload{color:#0000ff;}",
				      button_text_top_padding : 1,
				      button_text_left_padding : 18,
				      button_width: 80,
				      button_height: 20,
				      button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
				      button_cursor: SWFUpload.CURSOR.HAND,
				      
				      file_queued_handler : fileQueued,
				      file_queue_error_handler : fileQueueError,
				      file_dialog_complete_handler : fileDialogComplete,
				      upload_start_handler : uploadStart,
				      upload_progress_handler : uploadProgress,
				      upload_error_handler : uploadError,
				      upload_success_handler : uploadSuccessOver,
				      upload_complete_handler : uploadComplete,
				      queue_complete_handler : queueCompleteOver
				    };
				    swfupload = new SWFUpload(settings);
				    
				});
			
		 function uploadSuccessOver(file, serverData){
				  try {
				    var progress = new FileProgress(file, this.customSettings.progressTarget);
				    progress.toggleCancel(false);
				    var json = null;
				    json = serverData.evalJSON();
				    if(json.rtState=="1") {
				       progress.setError();
				       progress.setStatus("上传失败");
				    } else {
				       if($('attachmentId').value!=null && $('attachmentId').value!=""){
				    	 $('attachmentId').value += ',' + json.rtData.attachmentId;
				       } 
				       else{
				    	   $('attachmentId').value = json.rtData.attachmentId;
				       }
				       if($('attachmentName').value!=null && $('attachmentName').value!=""){
				    	 $('attachmentName').value += '*' + json.rtData.attachmentName;
				       } 
				       else{
				    	   $('attachmentName').value = json.rtData.attachmentName;
				       }
				    }
				  } catch (ex) {
				    this.debug(ex);
				  }
		}
		function queueCompleteOver(){
			var attachmentIds = $("attachmentId").value;
		    var attachmentNames = $("attachmentName").value;
		    if(attachmentIds){
		      jQuery('#attaTr').show();
	       	  jQuery('#fsUploadArea').hide();
	       	  attachMenuUtil("showAtt",null,null,attachmentNames,attachmentIds,false,'attach');
		    }
		 }
				 
		  function deleteAttachment(attachmentId,attachmentName){
			  var attrIds = $("attachmentId").value;
		    var attrNames = $("attachmentName").value;
		     var attrIdArrays = attrIds.split(",");
			  var attrNameArrays = attrNames.split("*");
			 var idArray = new Array();
			 var nameArray = new Array();
			 
			 for(var i=0;i<attrIdArrays.length;i++){
				 if(attrIdArrays[i] != attachmentId){
					 idArray.push(attrIdArrays[i]);
					 nameArray.push(attrNameArrays[i]);
				 }
			 }
			 $("attachmentId").value = idArray.join(",");
			 $("attachmentName").value = nameArray.join("*");
			 if($("attachmentId").value == ""){
				 jQuery('#attaTr').hide();
			 }
		  }
		  
		  function doSearch()
			{
				var searchValue = jQuery('#searchValue').val();
				jQuery('#gd_admin_id').combogrid("grid").datagrid('load',{
					searchValue:searchValue
				});
			}
		  function doSearch1()
			{
				var searchValue = jQuery('#searchValue1').val();
				var type_id = jQuery('#type_id').val();
				jQuery('#gd_worker_id').combogrid("grid").datagrid('load',{
					searchValue:searchValue,
					type_id:type_id
				});
			}
		  function domSearch()
			{
				var mSearchValue = jQuery('#mSearchValue').val();
				var material_type_id = jQuery('#material_type_id').combotree('getValue');
				jQuery(combogridTarget).combogrid('grid').datagrid('load',{
					searchValue:mSearchValue,
					material_type_id:material_type_id
					});
			}
		  
		  function deleteRow(){
			  jQuery('#table').datagrid('acceptChanges');
				lastIndex =-1;
				var rows = jQuery('#table').datagrid('getSelections');
				if (rows.length > 0){
					for(var i=0;i<rows.length;i++){
						var row = rows[i];
						var index = jQuery('#table').datagrid('getRowIndex', row);
						jQuery('#table').datagrid('deleteRow', index);
					}
				}
				var data = jQuery('#table').datagrid('getData');
				jQuery('#table').datagrid('loadData',data);
			}
		  function deleteFBRow(){
			  jQuery('#fb_detail').datagrid('acceptChanges');
				fb_lastIndex =-1;
				var rows = jQuery('#fb_detail').datagrid('getSelections');
				if (rows.length > 0){
					for(var i=0;i<rows.length;i++){
						var row = rows[i];
						var index = jQuery('#fb_detail').datagrid('getRowIndex', row);
						jQuery('#fb_detail').datagrid('deleteRow', index);
					}
				}
				var data = jQuery('#fb_detail').datagrid('getData');
				jQuery('#fb_detail').datagrid('loadData',data);
			}
		  function deleteMRow(){
			  jQuery('#material').datagrid('acceptChanges');
				m_lastIndex =-1;
				var rows = jQuery('#material').datagrid('getSelections');
				if (rows.length > 0){
					for(var i=0;i<rows.length;i++){
						var row = rows[i];
						var index = jQuery('#material').datagrid('getRowIndex', row);
						jQuery('#material').datagrid('deleteRow', index);
					}
				}
				var data = jQuery('#material').datagrid('getData');
				jQuery('#material').datagrid('loadData',data);
			}
		  function addRow(){
				jQuery('#table').datagrid('endEdit', lastIndex);
				jQuery('#table').datagrid('appendRow',{
					plan_start_time:'',
					plan_end_time:'',
					plan_content:''
				});
				var data = jQuery('#table').datagrid('getData');
				jQuery('#table').datagrid('loadData',data);
				lastIndex = jQuery('#table').datagrid('getRows').length-1;
				jQuery('#table').datagrid('selectRow', lastIndex);
				jQuery('#table').datagrid('beginEdit', lastIndex);
			}
		  function addFBRow(){
				jQuery('#fb_detail').datagrid('endEdit', fb_lastIndex);
				jQuery('#fb_detail').datagrid('appendRow',{
					fb_item_name:'',
					budget:'',
					budget_remark:''
				});
				var data = jQuery('#fb_detail').datagrid('getData');
				jQuery('#fb_detail').datagrid('loadData',data);
				fb_lastIndex = jQuery('#fb_detail').datagrid('getRows').length-1;
				jQuery('#fb_detail').datagrid('selectRow', fb_lastIndex);
				jQuery('#fb_detail').datagrid('beginEdit', fb_lastIndex);
			}
		  function addMRow(){
				jQuery('#material').datagrid('endEdit', m_lastIndex);
				jQuery('#material').datagrid('appendRow',{
				});
				var data = jQuery('#material').datagrid('getData');
				jQuery('#material').datagrid('loadData',data);
				m_lastIndex = jQuery('#material').datagrid('getRows').length-1;
				jQuery('#material').datagrid('selectRow', m_lastIndex);
				jQuery('#material').datagrid('beginEdit', m_lastIndex);
			}
		  var hasSubmit = 0;
		  function onFinishCallback() {
			  if(hasSubmit == 0){
				  hasSubmit = 1;
			  }else{
				  return;
			  }
			  jQuery('#table').datagrid('acceptChanges');
				lastIndex =-1;
			  jQuery('#fb_detail').datagrid('acceptChanges');
				fb_lastIndex =-1;
				//工单基本属性
			  var customer_id = jQuery('#customer_id').combogrid('getValue');
			  var customer = jQuery('#customer_id').combogrid('getText');
			  var xm_id = jQuery('#xm_id').val();
			  var xm_name = jQuery('#xm_name').val();
			  var xm_code = jQuery('#xm_code').val();
			  var gd_code = jQuery('#gd_code').val();
			  var gd_name = jQuery('#gd_name').val();
			  var gd_depand_id = jQuery('#gd_depand_id').combobox('getValue');
			  var gd_depand_name = jQuery('#gd_depand_id').combobox('getText');
			  var gd_sender = jQuery('#gd_sender').val();
			  var gd_notice_time=jQuery('#gd_notice_time').datebox('getValue');
			  var gd_admin_id=jQuery('#gd_admin_id').combogrid('getValue');
			  var gd_admin_name=encodeURIComponent(jQuery('#gd_admin_id').combogrid('getText'));
			  var dept_id = jQuery('#dept_id').val();
			  var dept_name = jQuery('#dept_name').val();
			  var gd_content = encodeURIComponent(jQuery('#gd_content').val());
			  var gd_detail_type_name = jQuery('#gd_detail_type_name').val();
			  var gd_total_time = jQuery('#gd_total_time').numberbox('getValue');
			  var gd_start=jQuery('#gd_start').datebox('getValue');
			  var gd_will_end=jQuery('#gd_will_end').datebox('getValue');
			  var gd_worker_id = jQuery('#gd_worker_id').combogrid('getValue');
			  var gd_worker_name = jQuery('#gd_worker_id').combogrid('getText');
			  var gd_worker_person = jQuery('#gd_worker_person').val();
			  var attachmentId = jQuery('#attachmentId').val();
			  var alarm_time = jQuery('#alarm_time').datebox('getValue');
			  var control = jQuery('#control').numberbox('getValue');
			  var company1_id = jQuery('#company1_id').combogrid('getValue');
			  var company1 = encodeURIComponent(jQuery('#company1_id').combogrid('getText'));
			  var company2_id = jQuery('#company2_id').combogrid('getValue');
			  var company2 = encodeURIComponent(jQuery('#company2_id').combogrid('getText'));
			  //任务计划
			  var plans="";
			  var jsondata=jQuery("#table").datagrid("getData");
			  for(var i=0;i<jsondata.total;i++){
				 if(plans!=""){
					 plans+=";";
				 }
				 plans+=jsonToStr(jsondata.rows[i]);
			  }
			  plans = encodeURIComponent(plans);
			  //分包预算
			  var details="";
			  var jsondata=jQuery("#fb_detail").datagrid("getData");
			  for(var i=0;i<jsondata.total;i++){
				 if(details!=""){
					 details+=";";
				 }
				 var index = jQuery("#fb_detail").datagrid("getRowIndex",jsondata.rows[i])+1;
				 if(jsondata.rows[i].fb_item_name == null || jsondata.rows[i].fb_item_name == ""){
					jQuery.messager.alert('提示','分包预算第'+index+'行未选择分包栏目！');
					return ;
				 }else if(jsondata.rows[i].budget == null || jsondata.rows[i].budget <= 0){
					jQuery.messager.alert('提示','分包预算第'+index+'行预算成本填写不正确！');
					return ;
				 }
				 details+=jsonToStr(jsondata.rows[i]);
			  }
			  if(details == ""){
				  jQuery.messager.alert('提示','分包预算还没填写！');
					return ;
			  }
			  details = encodeURIComponent(details);
			  //材料预算
			  var materials="";
			  var jsondata=jQuery("#material").datagrid("getData");
			  for(var i=0;i<jsondata.total;i++){
				 if(materials!=""){
					 materials+=";";
				 }
				 var index = jQuery("#material").datagrid("getRowIndex",jsondata.rows[i])+1;
				 if(jsondata.rows[i].name == null || jsondata.rows[i].name == ""){
					jQuery.messager.alert('提示','材料预算第'+index+'行未选择材料！');
					return ;
				 }else if(jsondata.rows[i].num == null || jsondata.rows[i].num <= 0){
					jQuery.messager.alert('提示','材料预算第'+index+'行数量填写不正确！');
					return ;
				 }
				 materials+=jsonToStr(jsondata.rows[i]);
			  }
			  if(materials == ""){
				  jQuery.messager.alert('提示','材料预算还没填写！');
					return ;
			  }
			  materials = encodeURIComponent(materials);
			  
			var param = "customer_id="+customer_id+"&customer="+customer+"&xm_id="+xm_id+"&xm_code="+xm_code+"&xm_name="+xm_name+"&gd_code="+gd_code+"&gd_name="+gd_name
					   +"&gd_depand_id="+gd_depand_id+"&gd_depand_name="+gd_depand_name+"&gd_sender="+gd_sender+"&gd_notice_time="+gd_notice_time
					   +"&gd_admin_id="+gd_admin_id+"&gd_admin_name="+gd_admin_name+"&dept_id="+dept_id+"&dept_name="+dept_name
					   +"&gd_content="+gd_content+"&gd_detail_type_name="+gd_detail_type_name+"&gd_total_time="+gd_total_time+"&gd_start="+gd_start
					   +"&gd_will_end="+gd_will_end+"&gd_worker_id="+gd_worker_id+"&gd_worker_name="+gd_worker_name+"&gd_worker_person="+gd_worker_person
					   +"&attachmentId="+attachmentId+"&plans="+plans+"&details="+details+"&materials="+materials+"&alarm_time="+alarm_time+"&control="+control+"&company1_id="+company1_id+"&company1="+company1
					   +"&company2_id="+company2_id+"&company2="+company2;
			jQuery.ajax({
				type:'POST',
				<%=isAdd?"url:'"+contextPath+"/springMVC/gd/addGDMain',":"url:'"+contextPath+"/springMVC/gd/updateGDMain?gd_id="+gd_id+"&gd_content_id="+gd_content_id+"',"%>				
				data:param,
				success:function(rtJson){
					if (rtJson.rtState == '0'){
						eval('window.opener.<%=callback%>();');
						window.close();
					}else{
						warningInfo(rtJson.rtMsrg);
					}
				}
			});
		}
		  function doSearchc()
			{
				var searchValue = jQuery('#searchValuec').val();
				var type_id = jQuery('#customer_type_id').combotree('getValue');
				jQuery('#customer_id').combogrid("grid").datagrid('load',{
					searchValue:searchValue,
					type_id:type_id
				});
			}
		  function choseXm(){
		    	openWindow("<%=contextPath %>/springViews/xm/choseMyXM.jsp?addGDAction=1","项目选择",1000, 800);
		    }
		  function rtCallBackXmSet(xm_id,xm_code,xm_name){
			  jQuery("#xm_id").val(xm_id);
		      jQuery("#xm_code").val(xm_code);
		      jQuery("#xm_name").val(xm_name);
		}
		</script>
	</head>
	<body>
		<div >
		<table align="center" border="0" cellpadding="0" cellspacing="0" style="height: 100%;width:100%">
			<tr>
				<td>
					<!-- Smart Wizard -->
					<div id="wizard" class="swMain">
						<ul>
							<li>
								<a href="#step-1"> <label class="stepNumber">
										1
									</label> <span class="stepDesc"> 派工单<br /> <small></small> </span> </a>
							</li>
							<li>
								<a href="#step-2"> <label class="stepNumber">
										2
									</label> <span class="stepDesc"> 任务计划<br /> <small></small> </span> </a>
							</li>
							<li>
								<a href="#step-3"> <label class="stepNumber">
										3
									</label> <span class="stepDesc"> 分包预算<br /> <small></small> </span> </a>
							</li>
							<li>
								<a href="#step-4"> <label class="stepNumber">
										4
									</label> <span class="stepDesc"> 材料预算<br /> <small></small> </span> </a>
							</li>
						</ul>
						<div id="step-1" style="width:700px;height:550px">
							<form id="gdForm">
							<table  style="border-collapse: collapse;" border="1px" bordercolor="#0eb83a" >
								<tr>
									 <td align="right" nowrap class="td1">
										客户：
									</td>
									<td class="td2" nowrap>
										<input id="customer_id" name="customer_id" data-options="required:true">
									</td>
									<td align="right" nowrap class="td1">
										工单依据：
									</td>
									<td class="td2" nowrap >
										<input id="gd_depand_id"  name="gd_depand_id" class="easyui-combobox" data-options="required:true,valueField:'id',textField:'text',url:'<%=contextPath %>/springMVC/group/getSystemTypeBox?type=3'" /> 
									</td>
								</tr>
								<tr>
									 <td align="right" nowrap class="td1">
										项目名称：
									</td>
									<td class="td2" nowrap>
										<input type="hidden" id="xm_id" name="xm_id"  >
										<input type="text" id="xm_name" name="xm_name" readOnly onclick="choseXm();">
										<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:false" onclick="choseXm();"></a>
									</td>
								  <td align="right" nowrap class="td1">
										项目编号：
									</td>
									<td class="td2" nowrap>
										
										<input type="text" id="xm_code" name="xm_code" readOnly>
									</td>
								</tr>
								<tr>
									 <td align="right" nowrap class="td1">
										工单名称：
									</td>
									<td class="td2" nowrap>
										<input type="text" id="gd_name" name="gd_name" class="easyui-validatebox" data-options="required:true">
									</td>
								  <td align="right" nowrap class="td1">
										工单编号：
									</td>
									<td class="td2" nowrap>
										<input type="text" id="gd_code" name="gd_code" class="easyui-validatebox" data-options="required:true">
									</td>
								</tr>
								<tr>
									<td align="right"  nowrap class="td1">
										派单人：
									</td>
									<td class="td2" nowrap >
										<input type="text" id="gd_admin_id" name="gd_admin_id" data-options="required:true">
									</td>
									<td align="right"  nowrap class="td1">
										所属部门：
									</td>
									<td class="td2" nowrap >
										<input type="hidden" id="dept_id" name="dept_id">
										<input type="text" id="dept_name" name="dept_name" readOnly>
									</td>
								</tr>
								<tr>
									<td align="right"  nowrap class="td1">
										发包人：
									</td>
									<td class="td2" nowrap >
										<input type="text" id="gd_sender" name="gd_sender"  class="easyui-validatebox" data-options="required:true">
									</td>
									<td align="right"  nowrap class="td1">
										通知日期：
									</td>
									<td class="td2" nowrap >
										<input id="gd_notice_time" name="gd_notice_time" class="easyui-datebox" data-options="required:true"/>
									</td>
								</tr>
								<tr>
									<td align="right"  nowrap class="td1">
										主要工作量及实施要求：
									</td>
									<td class="td2" nowrap colspan="3">
										<textarea id="gd_content" name="gd_content" class="easyui-validatebox" data-options="required:true" style="height:100%;width:100%" rows="6"></textarea>
									</td>
								</tr>
								<tr>
									<td align="right"  nowrap class="td1">
										细分专业：
									</td>
									<td class="td2" nowrap >
										<input type="text" id="gd_detail_type_name" name="gd_detail_type_name" class="easyui-validatebox" data-options="required:true"/>
									</td>
									<td align="right"  nowrap class="td1">
										总工时数：
									</td>
									<td class="td2" nowrap >
										<input id="gd_total_time" name="gd_total_time" class="easyui-numberbox" data-options="precision:3,required:true"/>
									</td>
								</tr>
								<tr>
									<td align="right"  nowrap class="td1">
										要求工期：
									</td>
									<td class="td2" nowrap >
										<input id="gd_start" name="gd_start" class="easyui-datebox" required="required"/>
									</td>
									<td align="right"  nowrap class="td1" style="text-align:center;font-size: 20px;font-weight: bold;">
										至
									</td>
									<td class="td2" nowrap >
										<input id="gd_will_end" name="gd_will_end" class="easyui-datebox" required="required"/>
									</td>
									
								</tr>
								<tr>
									<td align="right"  nowrap class="td1">
										预警时间：
									</td>
									<td class="td2" nowrap >
										<input id="alarm_time" name="alarm_time" class="easyui-datebox" required="required"/>
									</td>
									<td align="right"  nowrap class="td1">
										材料管控精度：
									</td>
									<td class="td2" nowrap >
										<input id="control" name="control" class="easyui-numberbox" data-options="precision:2,required:true" /> %
									</td>
								</tr>
								<tr>
									<td align="right"  nowrap class="td1">
										管理公司：
									</td>
									<td class="td2" nowrap >
										<input id="company1_id" name="company1_id" data-options="required:true"/>
									</td>
									<td align="right"  nowrap class="td1">
										实施公司：
									</td>
									<td class="td2" nowrap >
										<input id="company2_id" name="company2_id" data-options="required:true"/>
									</td>
								</tr>
								<tr>
									<td align="right"  nowrap class="td1">
										收单单位：
									</td>
									<td class="td2" nowrap >
										<input type="text" id="gd_worker_id" name="gd_worker_id"  data-options="required:true">
									</td>
									<td align="right"  nowrap class="td1">
										实施负责人：
									</td>
									<td class="td2" nowrap >
										<input type="text" id="gd_worker_person" name="gd_worker_person"  class="easyui-validatebox" data-options="required:true">
									</td>
								</tr>
									<tr id="attaTr" style="display:none">
								      <td nowrap class="td1">附件明细: </td>
								      <td class="td2" colspan='3'>
								        <input type="hidden" id="attachmentId" name="attachmentId">
								        <input type="hidden" id="attachmentName" name="attachmentName">
								        <span id="showAtt">
								        </span>
								      </td>
							   	    </tr>
								<tr>
							      <td nowrap class="td1">附件：</td>
							      <td class="td2" colspan='3'>
							        	 <div id="fsUploadArea" class="flash" style="width:380px;">
										     <div id="fsUploadProgress"></div>
										     <div>
										       <input type="button" id="btnStart" class="SmallButtonW" value="开始上传" onclick="swfupload.startUpload();" disabled="disabled">&nbsp;&nbsp;
										       <input type="button" id="btnCancel" class="SmallButtonW" value="全部取消" onclick="javascript:swfupload.cancelQueue();jQuery('#fsUploadArea').hide();" disabled="disabled">&nbsp;&nbsp;
										    </div>
									      </div>
									      
										    <div id="attachment1">
									          <span id="spanButtonUpload" title="上传附件"></span>
									        </div>
							      </td>
					   		   </tr>
				 			</table>
				 			</form>
						</div>
						<div id="step-2" style="width:700px;height:550px">
							<div id="table" ></div>
						</div>
						<div id="step-3" style="width:700px;height:550px">
							<div id="fb_detail" ></div>
						</div>
						<div id="step-4" style="width:700px;height:550px">
							<div id="material" ></div>
						</div>
					</div>
					<!-- End SmartWizard Content -->
				</td>
			</tr>
		</table>
		</div>
		<div id="tb" style="padding:3px;height:auto">
			<div align="right">
				查询条件：<input id="searchValue" name="searchValue" style="width:150px" title="用户名称或者用户真实姓名"/>
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
			</div>
		</div>
		<div id="tb1" style="padding:3px;height:auto">
			<div align="right">
				分类：<select id="type_id" class="" name="type_id"  onchange="doSearch1()">   
					     <option value="" selected></option> 
					    <option value="0">内部班组</option>   
					    <option value="1">外部分包商</option>   
					</select>  
				查询条件：<input id="searchValue1" name="searchValue1" style="width:150px" title="分包商名称或负责人"/>&nbsp;&nbsp;
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch1();"></a>
			</div>
		</div>
		<div id="tbc" style="padding:3px;height:auto">
			<div align="right">
				分类：<input  id="customer_type_id" name="customer_type_id" class="easyui-combotree">
				查询条件：<input id="searchValuec" name="searchValuec" style="width:150px" title="客户名称或联系人"/>&nbsp;&nbsp;
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearchc();"></a>
			</div>
		</div>
		<div id="mtb" style="padding:3px;height:auto">
				<div align="right">
					分类：<input  id="material_type_id" name="material_type_id" class="easyui-combotree">
					查询条件：<input id="mSearchValue" name="mSearchValue" style="width:150px" title="材料编码或名称"/>
					<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="domSearch();"></a>
				</div>
			</div>
	</body>
</html>


